package com.zlsy.learning.leetcode.arraycorrelation.array1464;

/**
 * @author zhouliang
 * @date 2020/7/23 20:51
 */
public class MaxProduct {
  public static int maxProduct(int[] nums) {
    int i = 0;
    int j = 0;

    if (nums.length <= 2) {
      return (nums[0] - 1) * (nums[1] - 1);
    }

    i = nums[0];
    for (int k = 1; k < nums.length; k++) {
      if (i <= nums[k]) {
        j = i;
        i = nums[k];
      } else if (j <= nums[k]) {
        j = nums[k];
      }
    }
    return (i - 1) * (j - 1);
  }

  public static void main(String[] args) {

  }
}
